package com.ruoyi.system.controller.front;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import com.ruoyi.system.controller.CxBase;
import com.ruoyi.system.domain.StudentInfo;
import com.ruoyi.system.domain.front.FrontMerchantInfo;
import com.ruoyi.system.domain.front.FrontUserInfo;
import com.ruoyi.system.domain.front.RecommendPage;
import com.ruoyi.system.domain.front.SafetyExaminationFrontInfo;
import com.ruoyi.system.service.front.IMerchantFrontService;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CaseInfo;
import com.ruoyi.system.service.ICaseInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 案件信息Controller
 *
 * @author ruoyi
 * @date 2021-04-07
 */
@RestController
@RequestMapping("/system/front/merchantfront")
public class MerchantFrontController extends CxBase {
    @Autowired
    private IMerchantFrontService merchantFrontService;

    protected final org.slf4j.Logger logger = LoggerFactory.getLogger(BaseController.class);

    /**
     * 查询页面广告
     *
     */
    @GetMapping("/selectrecommend")
    public TableDataInfo selectrecommend(RecommendPage recommendPage)
    {
        logput(null,Thread.currentThread().getStackTrace()[1].getMethodName(),this.getClass());
        TableDataInfo tableDataInfo = getDataTable(merchantFrontService.selectrecommend(recommendPage));
        logout(tableDataInfo,Thread.currentThread().getStackTrace()[1].getMethodName(),this.getClass());
        return tableDataInfo;
    }

    /**
     * 学生领取奖品
     *
     */
    @PostMapping("/updatePrizeType")
    public TableDataInfo updatePrizeType(@RequestBody FrontUserInfo frontUserInfo)
    {
        logput(frontUserInfo,Thread.currentThread().getStackTrace()[1].getMethodName(),this.getClass());
        logger.info(frontUserInfo.getCodeInfo());
        TableDataInfo tableDataInfo;
        int i = merchantFrontService.updatePrizeType(frontUserInfo.getCodeInfo());
        if(i>0){
            tableDataInfo = getDataTable("领取成功");
        }
        else if(i==-1)
            tableDataInfo = getDataTable("已领取过");
        else
            tableDataInfo = getDataTable("领取失败");
        logout(tableDataInfo,Thread.currentThread().getStackTrace()[1].getMethodName(),this.getClass());
        return tableDataInfo;
    }

    /**
     * 查询商户提供奖品列表数据
     *
     */
    @PostMapping("/selectMerchantPrizeInfo")
    public TableDataInfo selectMerchantPrizeInfo(@RequestBody FrontMerchantInfo frontMerchantInfo)
    {
        logput(frontMerchantInfo,Thread.currentThread().getStackTrace()[1].getMethodName(),this.getClass());
        TableDataInfo tableDataInfo = getDataTable(merchantFrontService.selectMerchantPrizeInfo(frontMerchantInfo));
        logout(tableDataInfo,Thread.currentThread().getStackTrace()[1].getMethodName(),this.getClass());
        return tableDataInfo;
    }

    /**
     * 商户登录
     *
     */
    @PostMapping("/loginMerchant")
    public TableDataInfo loginMerchant(@RequestBody FrontMerchantInfo frontMerchantInfo)
    {
        logput(frontMerchantInfo,Thread.currentThread().getStackTrace()[1].getMethodName(),this.getClass());
        List<FrontMerchantInfo> frontMerchantInfos = new ArrayList<>();
        frontMerchantInfos.add(merchantFrontService.loginMerchant(frontMerchantInfo));
        TableDataInfo tableDataInfo;
        if(frontMerchantInfos.get(0)==null){
            tableDataInfo = getDataTable(1,"登陆失败");
        }
        else {
            tableDataInfo = getDataTable(frontMerchantInfos);
        }
        logout(tableDataInfo,Thread.currentThread().getStackTrace()[1].getMethodName(),this.getClass());
        return tableDataInfo;
    }
}

